define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_shoper_auth/index' + location.search,
                    add_url: 'user_shoper_auth/add',
                    edit_url: 'user_shoper_auth/edit',
                    del_url: 'user_shoper_auth/del',
                    multi_url: 'user_shoper_auth/multi',
                    import_url: 'user_shoper_auth/import',
                    table: 'user_shoper_auth',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                dblClickToEdit: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,//通用搜索是否显示
                commonSearch: true,
                search: false, //文本框搜索
                showSearch: false,//隐藏放大镜
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'id_card_front_image', title: __('Id_card_front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'id_card_back_image', title: __('Id_card_back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE'},
                        {field: 'examine_status', title: __('Examine_status'), searchList: {"0":__('Examine_status 0'),"1":__('Examine_status 1'),"2":__('Examine_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'examine_time', title: __('Examine_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'reason', title: __('Reason'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {
                            field: 'operate', 
                            title: __('Operate'), 
                            table: table, 
                            events: Table.api.events.operate, 
                            buttons:[
                                {
                                    name: 'examine_status',
                                    title: __('审核通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    confirm: '确认审核通过？',
                                    url: 'user_shoper_auth/examine_status',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg);
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    visible: function (row) {
                                        if (row.examine_status != 0) {
                                            return false;
                                        } else {
                                            //返回true时按钮显示,返回false隐藏
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'examine_status',
                                    title: __('审核拒绝'),
                                    // text: __('驳回'),
                                    extend: 'data-area=\'["50%","50%"]\'',
                                    classname: 'btn btn-xs btn-danger btn-execute btn-dialog',
                                    icon: 'fa fa-times',
                                    url: function (row) {
                                        return "user_shoper_auth/reject?ids=" + row.id
                                    },
                                    visible: function (row) {
                                        if (row.examine_status != 0) {
                                            return false;
                                        } else {
                                            //返回true时按钮显示,返回false隐藏
                                            return true;
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'user_shoper_auth/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'user_shoper_auth/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'user_shoper_auth/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        reject: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
